/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "screen_session_manager_client/include/screen_session_manager_client.h"
#include "session/host/include/ws_snapshot_helper.h"

namespace OHOS::Rosen {
namespace {
const std::unordered_map<int32_t, DisplayOrientation> ROTATION_TO_DISPLAYORIENTATION_MAP = {
    { PORTRAIT_ANGLE, DisplayOrientation::PORTRAIT },
    { LANDSCAPE_ANGLE, DisplayOrientation::LANDSCAPE },
    { PORTRAIT_INVERTED_ANGLE, DisplayOrientation::PORTRAIT_INVERTED },
    { LANDSCAPE_INVERTED_ANGLE, DisplayOrientation::LANDSCAPE_INVERTED }
};
}

uint32_t WSSnapshotHelper::GetScreenStatus()
{
    FoldStatus foldStatus = ScreenSessionManagerClient::GetInstance().GetFoldStatus();
    return GetScreenStatus(foldStatus);
}

uint32_t WSSnapshotHelper::GetScreenStatus(FoldStatus foldStatus)
{
    if (static_cast<int>(foldStatus) % SCREEN_FOLDED == 0) {
        return SCREEN_FOLDED;
    } else if (foldStatus == FoldStatus::EXPAND || foldStatus == FoldStatus::HALF_FOLD) {
        return SCREEN_EXPAND;
    }
    return SCREEN_UNKNOWN;
}

DisplayOrientation WSSnapshotHelper::GetDisplayOrientation(int32_t rotation)
{
    if (ROTATION_TO_DISPLAYORIENTATION_MAP.count(rotation)) {
        return ROTATION_TO_DISPLAYORIENTATION_MAP.at(rotation);
    }
    return DisplayOrientation::PORTRAIT;
}
} // namespace OHOS::Rosen